/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sis.studentinfo;

import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Admin
 */
public class Name {

    private String firstName = "";
    private String middleName = "";
    private String lastName = "";

    /***
     * Constructs a new Name by tokenizing the input String by spaces
     * The First token will be the First Name
     * The last token will be Last Name
     * 
     * @param fullName 
     */
    public Name(String fullName) {
        ValidateUtil.checkNullEmpty(new SimpleEntry("fullname", fullName));
        String[] names = fullName.split(" ");
        
        if (names.length != 2) {
            throw new IllegalArgumentException("Full Name must include a First and Last Name");
        }
        setFirstName(names[0]);
        setLastName(names[1]);

    }

    public Name(String firstName, String middleName, String lastName) {
        setFirstName(firstName);
        setMiddleName(middleName);
        setLastName(lastName);
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        ValidateUtil.checkNullEmpty(new SimpleEntry("firstName", firstName));
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        ValidateUtil.checkNullEmpty(new SimpleEntry("lastName", lastName));
        this.lastName = lastName;
    }

    public String getMiddleName() {
        return middleName;
    }
/****
     * Sets the Middle Name
     * This Value can be left empty if Name does not contain a Middle Name
     * @param middleName 
     */
    public void setMiddleName(String middleName) {
        ValidateUtil.checkNull(new SimpleEntry("middleName", middleName));
        this.middleName = middleName;
    }

    public String getFullName() {
        if (middleName.isEmpty()) {
            return this.getFirstName() + " " + this.lastName;
        }
        return this.getFirstName() + " " + this.getMiddleName() + " " + this.lastName;

    }

    @Override
    public String toString() {
        return this.getFullName();
    }

    @Override
    public Name clone() {
        return new Name(this.getFirstName(), this.getMiddleName(), this.getLastName());
    }
}
